// let mysql = require('mysql')
const mysql = require('mysql2')
let connection = mysql.createConnection({
  host: 'localhost',
  user: 'root',
  password: '123456',
  database: 'congra'
})

connection.connect()
module.exports = connection
// 查询数据
// const sqlStr = 'select * from student'
// connection.query(sqlStr, function (error, results) {
//   if (error) throw error
//   console.log(results)
// })

// 插入数据
// const sqlStr = 'INSERT INTO student (  NAME, time, age ) VALUES (?, ?, ?)'
// const user = { NAME: '张三', time: '2019-08-07 15:34:06', age: 1 }
// connection.query(sqlStr, [user.NAME, user.time, user.age], function (error, results) {
//   if (error) throw error
//   console.log(results)
// })

// 2插入数据
// const sqlStr = 'INSERT INTO student SET ?'
// const user = { NAME: '李四', time: '2019-08-07 15:34:06', age: 101 }
// connection.query(sqlStr, user, function (error, results) {
//   if (error) throw error
//   console.log(results)
// })

// 3更新数据
// const user = { NAME: '李四101', time: '2019-08-07 15:34:06', age: 101, id: 7 }
// const sqlStr = 'UPDATE student SET ? WHERE id=?'
// connection.query(sqlStr, [user, user.id], function (error, results) {
//   if (error) throw error
//   console.log(results)
// })

// 4删除数据
// const sqlStr = 'DELETE FROM student WHERE id=7'
// connection.query(sqlStr, function (error, results) {
//   if (error) throw error
//   console.log(results)
// })

// 5软删除数据
// const user = { NAME: '李四101', time: '2019-08-07 15:34:06', status: 0, age: 101, id: 6 }
// const sqlStr = 'UPDATE student SET ? WHERE id=?'
// connection.query(sqlStr, [user, user.id], function (error, results) {
//   if (error) throw error
//   console.log(results)
// })

// connection.end()
